package com.gjy.test.mysql;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2022-11-10 14:50:12
 */
public class MUtil {

    public static Connection connection() {
        String path = "D:\\code\\java\\special-topic\\encryption\\src\\main\\resources\\mysql.properties";
        Properties properties = new Properties();
        try (FileInputStream fis = new FileInputStream(path)) {
            properties.load(fis);
            String driver = properties.getProperty("driver");
            String url = properties.getProperty("url");
            String username = properties.getProperty("username");
            String password = properties.getProperty("password");
            Class.forName(driver);
            return DriverManager.getConnection(url, username, password);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
